#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <limits.h>
using namespace std;
#include <vector>

int main() {
	int t = 0;
	cin >> t;
	while (t--) {
		string s, l, r;
		int m;
		cin >> s;
		cin >> m;
		cin >> l;
		cin >> r;
		vector<int> v;
		for (int i = 0; i < m; i++) {
			int max_j = INT_MIN;
			for (char c = l[i]; c <= r[i]; c++) {
				int flag = 0;
				for (int j = 0; j < s.size(); j++) {
					if (s[j] == c) {
						flag = 1;
						max_j = max(max_j, j);
					}
				}
				if (flag == 0) {
					max_j = s.size();
				}
			}
			v.push_back(max_j);
		}
		int flag = 0;
		for (int i = 0; i < v.size() - 1; i++) {
			if (v[i] > v[i + 1]) {
				flag = 1;
				cout << "NO" << endl;
				break;
			}
		}
		if (flag == 0) {
			cout << "YES" << endl;
		}
	}
	return 0;
}